﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using ALS.Communication.Contract;
using ALS.Component.Tools.Helpers;
using ALS.IRepository;

namespace ALS.Communication.Domain.Commends
{
    /// <summary>
    /// 命令基类
    /// </summary>
    public abstract class Cmd
    {
        /// <summary>
        /// 控制板仓储
        /// </summary>
        [Import(typeof(IDashboardRepository))]
        protected IDashboardRepository DashboardRepository { get; set; }

        /// <summary>
        /// 自动物流订单仓储
        /// </summary>
        [Import(typeof(IAlsOrderRepository))]
        protected IAlsOrderRepository AlsOrderRepository { get; set; }

        /// <summary>
        /// 运行
        /// </summary>
        /// <param name="requestBodyXml"></param>
        /// <returns></returns>
        public abstract Response Run(string requestBodyXml);

        /// <summary>
        /// 获取请求
        /// </summary>
        /// <param name="requestBodyXml"></param>
        /// <returns></returns>
        protected T_Request GetRequestBody<T_Request>(string requestBodyXml)
        {
            return SerializeHelper.Deserialize<T_Request>(requestBodyXml);
        }

        /// <summary>
        /// 获取响应
        /// </summary>
        /// <typeparam name="T_Response"></typeparam>
        /// <param name="responseBody"></param>
        /// <returns></returns>
        protected Response GetResponse<T_Response>(T_Response responseBody)
        {
            var response = new Response();
            response.ResponseBody = SerializeHelper.Serialize<T_Response>(responseBody);
            return response;
        }
    }
}
